import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import "./utils/init"
import "./assets/css/common.css"
import './assets/css/global.css'
import "./router/permissions"
import Global from "../src/assets/Global.vue"
import Chat from 'jwchat';
Vue.use(Chat)
import axios from 'axios'
Vue.prototype.$http = axios;

axios.defaults.baseURL = 'http://8.130.171.48:8080'
axios.interceptors.request.use(config => {
    console.log(config)
    config.headers.Authorization = window.sessionStorage.getItem('token')
        // 在最后必须return config
    return config
})
router.beforeEach((to, from, next) => {
    if (to.matched.some(res => res.meta.requireAuth)) { // 验证是否需要登陆
        var id = Global.login
        console.log(id)
        if (id) { // 查询本地存储信息是否已经登陆
            next()
        } else {
            next({
                path: '/adminLogin', // 未登录则跳转至login页面
                redirect: '/Welcome' // 登陆成功后回到当前页面，这里传值给login页面，to.fullPath为当前点击的页面
            })
        }
    } else {
        next()
    }
})
Vue.config.productionTip = false
    //设置浏览器标签
Vue.directive('title', {
    inserted: function(el, binding) {
        document.title = el.dataset.title
    }
})


new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')